package com.jlwl.houseservice.controller;

import com.jlwl.houseservice.common.Result;
import com.jlwl.houseservice.service.AdministratorService;
import com.jlwl.houseservice.service.UserService;
import com.jlwl.houseservice.vo.AdminLoginVO;
import com.jlwl.houseservice.vo.LoginResultVO;
import com.jlwl.houseservice.vo.UserLoginVO;
import com.jlwl.houseservice.vo.UserRegisterVO;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 认证控制器
 */
@RestController
@RequestMapping("/auth")
public class AuthController {

    @Autowired
    private AdministratorService administratorService;

    @Autowired
    private UserService userService;

    /**
     * 管理员登录
     */
    @PostMapping("/admin/login")
    public Result<LoginResultVO> adminLogin(@Valid @RequestBody AdminLoginVO adminLoginVO) {
        LoginResultVO loginResultVO = administratorService.login(adminLoginVO);
        return Result.success(loginResultVO);
    }

    /**
     * 用户登录
     */
    @PostMapping("/user/login")
    public Result<LoginResultVO> userLogin(@Valid @RequestBody UserLoginVO userLoginVO) {
        LoginResultVO loginResultVO = userService.login(userLoginVO);
        return Result.success(loginResultVO);
    }

    /**
     * 用户注册
     */
    @PostMapping("/user/register")
    public Result<LoginResultVO> userRegister(@Valid @RequestBody UserRegisterVO userRegisterVO) {
        LoginResultVO loginResultVO = userService.register(userRegisterVO);
        return Result.success(loginResultVO);
    }
} 